package com.sky.mapper;

import com.sky.anno.AutoFill;
import com.sky.entity.ShoppingCart;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

import static com.sky.enumeration.OperationType.INSERT;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 购物车查询
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 购物车修改数量
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNum(ShoppingCart shoppingCart);

    @AutoFill(INSERT)
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) VALUES " +
            "(#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void addShoppingCart(ShoppingCart shoppingCart);



    /**
     * 清空购物车接口
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void cleanShoppingCart(ShoppingCart shoppingCart);

    @Delete("delete from shopping_cart where id=#{id}")
    void deleteShoppingCart(Long id);

    /**
     * 再来一单
     */
    @AutoFill(INSERT)
    void addBatchShopping(List<ShoppingCart> shoppingCartList);
}
